import store from "@/wlkutils/store";
import share from "@/wlkutils/share";
import platform from "@/wlkutils/platform";
import { router } from '@/wlkutils/router';

export default {
	data() {
		return {

		};
	},
	onLoad(options) {
		// #ifdef MP
		if (options?.scene) {
			
			let path = uni.$u.pages();
			path = '/' + (path[path.length - 1] ? path[path.length - 1].route : '');
			uni.$u.http.post('common/getScene', { scene: options.scene }).then(res => {
				let scene = decodeURIComponent(res.data);
				let sceneObj = scene.split('-');
				var params = new Object();
				sceneObj.forEach(function(v, k) {
					let arr = v.split("=");
					if (arr.length == 2) {
						params[arr[0]] = arr[1];
					}
				});

				this.setShareAgentId(params);
				router.replace({
					path: path,
					query: params
				})
			}).catch(res => {

			})
		} else {
			this.setShareAgentId(options);
		}
		// #endif
		// #ifndef MP
		this.setShareAgentId(options);
		// #endif
	},
	onShow() {
		// #ifdef MP
		share.setShareInfo();
		// #endif
	},
	methods: {
		//推荐人
		setShareAgentId(options) {
			var agent_id = uni.$u.getProperty(options, 'user_id');
			if (!uni.$u.test.isEmpty(agent_id)) {
				if (store.getters.isLogin) {
					uni.$u.http.post("share/bindAgent", {
						agent_id: agent_id
					});
				} else {
					uni.setStorageSync('agent_id', agent_id);
				}
			}
		}
	},
}